package com.hx.miniblog;

import com.hx.miniblog.util.utils.APIUtils;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.text.ParseException;

@SpringBootApplication
@MapperScan("com.hx.miniblog.mapper")
@EnableScheduling
public class MiniBlogApplication {

    public static void main(String[] args) {
        SpringApplication.run(MiniBlogApplication.class, args);
    }

    @Scheduled(cron = "0 30 8 * * ? ")
    public void morningPush() throws ParseException {
        APIUtils.push(()->{
            WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
                    .toUser("ovXP15ikdZEJE0IVuKLtzsCgE9iA")
                    .toUser("ovXP15vkf7_pa3krwVfbJMXEEDeU")
                    .templateId("KjBMAx2a-7rFA5pdqPIZxIC17x_xStnUgy_Q9lkLPuE")
                    .build();

            try {
                APIUtils.collectMessage().forEach((k,v)->{

                    templateMessage.addData(new WxMpTemplateData(k,v,"#00BFFF"));
                });
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
            return templateMessage;
        });
    }



}
